package com.ohyes.bigbang.commons.base;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.beans.propertyeditors.CustomNumberEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;

import com.ohyes.bigbang.commons.propertyeditors.CustomNumEditor;

public class BaseController {
	
	public final String  COMMON_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
	
	@InitBinder
	protected void initBinder(WebDataBinder binder) throws Exception {
		SimpleDateFormat dateFormat = new SimpleDateFormat(COMMON_DATE_FORMAT);
		binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
		binder.registerCustomEditor(BigDecimal.class, new CustomNumberEditor(BigDecimal.class, false));
		binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
		
		//CustomNumEditor
		binder.registerCustomEditor(Integer.class, null, new CustomNumEditor(Integer.class, null, true));
		binder.registerCustomEditor(int.class, null, new CustomNumEditor(Integer.class, null, true));
		binder.registerCustomEditor(Long.class, null, new CustomNumEditor(Long.class, null, true));
		binder.registerCustomEditor(long.class, null, new CustomNumEditor(Long.class, null, true));
		
		binder.registerCustomEditor(Float.class, new CustomNumberEditor(Float.class, true));
		binder.registerCustomEditor(Double.class, new CustomNumberEditor(Double.class, true));
		binder.registerCustomEditor(BigInteger.class, new CustomNumberEditor(BigInteger.class, true));
		
	}

}
